package cn.com.bob.controller;


import cn.com.bob.api.MemberApi;
import cn.com.bob.dto.Msg;
import cn.com.bob.entity.Order;
import cn.com.bob.feign.OrderFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RefreshScope
public class MemberController implements MemberApi {


    @Autowired
    private OrderFeign orderFeign;

    @Value("${server.port}")
    private String port;

    @Value("${memberName}")
    private String userName;
    @Override
    public String getPort() {
        return "这是名字为 "+  userName + " 会员服务，端口号" + port;
    }

    @Override
    public String getMember() {
        return "这是名字为 "+  userName + " 会员服务，端口号" + port;
    }

    @GetMapping("/memberToOrder")
    public String memberToOrder(){
        return "这是会员服务调用订单服务 ，结果为： " + orderFeign.getPort();
    }

    @PostMapping("/memberBuyOrder")
    public Msg memberBuyOrder(@RequestBody Order order){
        System.out.println("这是会员购买商品" + order);
        return orderFeign.buyOrder(order);
    }
}
